﻿<?php
//Establish Session
session_start();
/**
 * @author Invisible Man
 * @copyright 2013
 */
//Callback all pages
if (isset($_SESSION['level'])) {
    header("location: index.php");
    exit();
}
require('../config.php');
//Before Enable
$page_title ='Trang chủ';
//Starting all pages
//Callback header
require('theme/default/header.php');
//Callback Content
//Checking input
if (isset($_POST['btnLogin'])) {
    //Checking Empty
    if (empty($_POST['txtUser'])) {
        echo '<p class="error_msg">Bạn chưa nhập tên User</p>';
    }
    elseif (empty($_POST['txtPass'])) {
        echo '<p class="error_msg">Bạn chưa nhập tên Password</p>';
    }
    else {
        //Connect Database
        require('../includes/db_connect.php');
        //Query
        $sql = 'SELECT * FROM member WHERE member_user="'.mb_strtolower($_POST['txtUser']).'" AND member_pass="'.md5($_POST['txtPass']).'"';
        $query = mysql_query($sql, $db_con);
        //Checking User Exist
        if (mysql_num_rows($query) == 0) {
            echo '<p class="error_msg">Sai thông tin đăng nhập</p>';
        }
        else {
            //Fill Data
            $data = mysql_fetch_assoc($query);
            //Session
            $_SESSION['id'] = $data['member_id'];
            $_SESSION['username'] = $data['member_user'];
            $_SESSION['password'] = $data['member_pass'];
            $_SESSION['level'] = $data['member_level'];
            echo '
            <script type="text/javascript">
                window.location = "index.php";
            </script> ';
            exit();
        }
    }
}
//FORM
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" style="width: 650px; margin: 30px auto;">
    <fieldset>
        <legend>Login</legend>
        <table>
            <tr>
                <td class="login_img"></td>
                <td>
                    <span class="form_label">Username:</span>
                    <span class="form_item"><input type="text" name="txtUser" class="textbox" maxlength="100"/></span><br />
                    <span class="form_label">Password:</span>
                    <span class="form_item"><input type="password" name="txtPass" class="textbox" maxlength="100" /></span><br />
                    <span class="form_label"></span>
                    <span class="form_item"><input type="submit" name="btnLogin" value="Login" class="button"/></span><br />
                </td>
            </tr>
        </table>
    </fieldset>
</form>';
//Callback Footer
require('theme/default/footer.php');
?>



